﻿package mortal.game.view.copy.groupCopy.view
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.greensock.layout.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.display.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;

    public class GroupcopyInviteCellRender extends GCellRenderer
    {
        private var _sGroupOper:SGroupOper;
        private var _sGroupCopyInvite:SGroupCopyInvite;
        private var _tcopy:TCopy;
        private var _avatar:GImageBitmap;
        private var _captainName:GTextFiled;
        private var _carrar:GTextFiled;
        private var _combat:GTextFiled;
        private var _level:GTextFiled;
        private var _num:GTextFiled;
        private var _copyName:GTextFiled;
        private var _teamMatNum:GTextFiled;
        private var _process:GTextFiled;
        private var _agreeBtn:GButton;
        private var _rejectBtn:GButton;

        public function GroupcopyInviteCellRender()
        {
            return;
        }// end function

        override protected function initSkin() : void
        {
            var _loc_1:* = GlobalClass.getBitmap(BitmapDataConst.AlphaBMD);
            var _loc_2:* = ResourceConst.getScaleBitmap(ImagesConst.selectedBg);
            this.setStyle("downSkin", _loc_2);
            this.setStyle("overSkin", _loc_2);
            this.setStyle("upSkin", _loc_1);
            this.setStyle("selectedDownSkin", _loc_2);
            this.setStyle("selectedOverSkin", _loc_2);
            this.setStyle("selectedUpSkin", _loc_2);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._avatar = UIFactory.gImageBitmap("", 3, 6, this);
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.align = AlignMode.CENTER;
            this._captainName = UIFactory.gTextField("", 42, 5, 160, 20, this, GlobalStyle.textFormatChen);
            this._carrar = UIFactory.gTextField("", 42, 28, 160, 20, this, GlobalStyle.textFormatHuang);
            this._combat = UIFactory.gTextField("", 87, 28, 160, 20, this, _loc_1.left());
            this._level = UIFactory.gTextField("", 2, 28, 160, 20, this, _loc_1.left());
            this._num = UIFactory.gTextField("", 145, 15, 100, 20, this, _loc_1.center());
            this._copyName = UIFactory.gTextField("", 255, 15, 100, 20, this, _loc_1.center());
            this._teamMatNum = UIFactory.gTextField("", 395, 15, 100, 20, this, _loc_1.center());
            _loc_1 = GlobalStyle.textFormatChen;
            _loc_1.align = AlignMode.CENTER;
            this._process = UIFactory.gTextField("", 510, 15, 100, 20, this, _loc_1);
            this._agreeBtn = UIFactory.gButton(Language.getString(30230), 655, 15, 40, 22, this);
            this._agreeBtn.configEventListener(MouseEvent.CLICK, this.clickAgreeHandler);
            this._rejectBtn = UIFactory.gButton(Language.getString(30231), 696, 15, 40, 22, this);
            this._rejectBtn.configEventListener(MouseEvent.CLICK, this.rejectHandler);
            this.pushUIToDisposeVec(UIFactory.bg(0, 52, 760, 1, this, ImagesConst.SplitLine));
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._captainName.dispose(param1);
            this._num.dispose(param1);
            this._copyName.dispose(param1);
            this._teamMatNum.dispose(param1);
            this._process.dispose(param1);
            this._agreeBtn.dispose(param1);
            this._rejectBtn.dispose(param1);
            this._carrar.dispose(param1);
            this._combat.dispose(param1);
            this._level.dispose(param1);
            this._avatar.dispose(param1);
            this._captainName = null;
            this._num = null;
            this._copyName = null;
            this._teamMatNum = null;
            this._process = null;
            this._agreeBtn = null;
            this._rejectBtn = null;
            this._carrar = null;
            this._combat = null;
            this._level = null;
            this._avatar = null;
            this._sGroupCopyInvite = null;
            this._sGroupOper = null;
            this._tcopy = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function alertAgreeHandler(param1:int) : void
        {
            if (param1 == Alert.OK)
            {
                this.agreeHandler();
                Dispatcher.dispatchEvent(new DataEvent(EventName.ArenaCancelSignUp));
            }
            return;
        }// end function

        private function agreeHandler() : void
        {
            var _loc_1:* = new Array();
            var _loc_2:* = new SGroupOper();
            _loc_2.fromEntityId = Cache.instance.role.entityInfo.entityId;
            _loc_2.toEntityId = this._sGroupOper.fromEntityId;
            _loc_2.fromPlayer = new SPublicPlayer();
            _loc_2.fromPlayer.guildId = new SEntityId();
            _loc_2.fromPlayer.copyId = new SEntityId();
            _loc_2.fromPlayer.entityId = Cache.instance.role.entityInfo.entityId;
            _loc_2.type = EGroupOperType._EGroupOperTypeAgree;
            _loc_2.uid = this._sGroupOper.uid;
            _loc_1.push(_loc_2);
            Dispatcher.dispatchEvent(new DataEvent(EventName.GroupInviteOper, _loc_1));
            GroupCopyInviteWin.instance.hide();
            return;
        }// end function

        private function clickAgreeHandler(event:MouseEvent) : void
        {
            if (GameController.arena.isMatching)
            {
                Alert.show(Language.getStringByParam(70890, this._tcopy.name), null, Alert.OK | Alert.CANCEL, null, this.alertAgreeHandler);
                return;
            }
            if (GameController.copy.heroArenaCopy.isMatching)
            {
                Alert.show(Language.getStringByParam(70891, this._tcopy.name), null, Alert.OK | Alert.CANCEL, null, this.alertAgreeHandler);
                return;
            }
            this.agreeHandler();
            return;
        }// end function

        private function rejectHandler(event:MouseEvent) : void
        {
            var _loc_2:* = new Array();
            var _loc_3:* = new SGroupOper();
            _loc_3.fromEntityId = Cache.instance.role.entityInfo.entityId;
            _loc_3.toEntityId = this._sGroupOper.fromEntityId;
            _loc_3.fromPlayer = new SPublicPlayer();
            _loc_3.fromPlayer.guildId = new SEntityId();
            _loc_3.fromPlayer.copyId = new SEntityId();
            _loc_3.fromPlayer.entityId = Cache.instance.role.entityInfo.entityId;
            _loc_3.type = EGroupOperType._EGroupOperTypeReject;
            _loc_3.uid = this._sGroupOper.uid;
            _loc_3.copyCode = this._sGroupOper.copyCode;
            _loc_2.push(_loc_3);
            Dispatcher.dispatchEvent(new DataEvent(EventName.GroupInviteReplyOper, _loc_2));
            return;
        }// end function

        private function setCareer(param1:int) : void
        {
            this._carrar.text = GameDefConfig.instance.getCarrer(param1);
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            this._sGroupCopyInvite = param1.data;
            this._sGroupOper = this._sGroupCopyInvite.groupOper;
            this._tcopy = CopyConfig.instance.getCopyInfoByCode(this._sGroupOper.copyCode);
            this._avatar.imgUrl = AvatarUtil.getPlayerAvatarUrl(this._sGroupOper.fromPlayer.career, this._sGroupOper.fromPlayer.sex, AvatarUtil.Small);
            if (this._sGroupOper)
            {
                this.setCareer(this._sGroupOper.fromPlayer.career);
                this._captainName.text = this._sGroupOper.fromPlayer.name;
                this._level.text = this._sGroupOper.fromPlayer.level.toString();
                this._combat.text = this._sGroupOper.fromPlayer.combat.toString();
            }
            this._num.text = this._sGroupOper.copyNum + Language.getString(70892);
            this._copyName.text = this._tcopy.name;
            this._process.text = this._sGroupCopyInvite.killNum + "/" + this._tcopy.totalBossNum;
            this._teamMatNum.text = this._sGroupOper.memberNum + "/5";
            return;
        }// end function

    }
}
